#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys, getopt

clients = 1 
PROGRAM_VERSION = "1.5"
_shortOpts =  "912Vfrt:p:c:?h"
benchtime = 30
   

def usage():
    print(
        "webbench [option]... URL\n"
        "  -f|--force               Don't wait for reply from server.\n"
        "  -r|--reload              Send reload request - Pragma: no-cache.\n"
        "  -t|--time <sec>          Run benchmark for <sec> seconds. Default 30.\n"
        "  -p|--proxy <server:port> Use proxy server for request.\n"
        "  -c|--clients <n>         Run <n> HTTP clients at once. Default one.\n"
        "  -9|--http09              Use HTTP/0.9 style requests.\n"
        "  -1|--http10              Use HTTP/1.0 protocol.\n"
        "  -2|--http11              Use HTTP/1.1 protocol.\n"
        "  --get                    Use GET request method.\n"
        "  --head                   Use HEAD request method.\n"
        "  --options                Use OPTIONS request method.\n"
        "  --trace                  Use TRACE request method.\n"
        "  -?|-h|--help             This information.\n"
        "  -V|--version             Display program version.\n"
        )

def main():
    
    global clients,PROGRAM_VERSION,_shortOpts,benchtime
    
    opts, args = getopt.getopt(sys.argv[1:], _shortOpts, longopts=[])
    
    '''print opts'''
    #没有参数
    if(len(opts)<=1):
        usage()
        quit()
    
    #没有地址
    if(len(args)==0):
        print "webbench: Missing URL!\n"
        quit()

    if(clients==0):
        clients=1
    if(benchtime==0):
        benchtime=60
    # Copyright */
    print "Webbench - Simple Web Benchmark ", PROGRAM_VERSION, "\n" , "Copyright (c) Dear Mrli 2016.\n"
        
if __name__ == '__main__':
    main()